<?php

function pre($data){
	echo "<pre>";print_r($data);echo "</pre>";
}

//URL安全的base64加密（+换-   /换_ 去掉“=”）
function enurl64($data) {
	return rtrim(strtr(base64_encode($data), '+/', '-_'), '=');
}

//URL安全的base64解密
function deurl64($data) {
	return base64_decode(strtr($data, '-_', '+/'));
}



function indent($json) {

	$result = '';
	$pos = 0;
	$strLen = strlen($json);
	$indentStr = '&nbsp;&nbsp;';
	$newLine = "<br>";
	$prevChar = '';
	$outOfQuotes = true;

	for ($i=0; $i<=$strLen; $i++) {

		// Grab the next character in the string.
		$char = substr($json, $i, 1);
		// Are we inside a quoted string?
		if ($char == '"' && $prevChar != '\\') {
			$outOfQuotes = !$outOfQuotes;
			// If this character is the end of an element,
			// output a new line and indent the next line.
		} else if(($char == '}' || $char == ']') && $outOfQuotes) {
			$result .= $newLine;
			$pos--;
			for ($j=0; $j<$pos; $j++) {
				$result .= $indentStr;
			}
		}
		// Add the character to the result string.
		$result .= $char;
		// If the last character was the beginning of an element,
		// output a new line and indent the next line.
		if (($char == ',' || $char == '{' || $char == '[') && $outOfQuotes) {
			$result .= $newLine;
			if ($char == '{' || $char == '[') {
				$pos++;
			}
			for ($j = 0; $j < $pos; $j++) {
				$result .= $indentStr;
			}
		}
		$prevChar = $char;
	}

	return $result;

}

?>